/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package e.odbo.data.impexp.model.transform;

import e.odbo.data.impexp.FieldGenerator;
import e.odbo.data.impexp.model.AbstractImpExpTableDefinition;

import java.util.ArrayList;
import java.util.List;

/**
 * 此类括展一般导入导出表类，用于某些表导入时的忽略字段的包装处理，其将直接屏蔽对应的字段
 *
 * @author Administrator
 */
public class SimpleTableTransform extends AbstractTableTransform {
    int[] ignoreIndexs;//用与设置其将忽略的字段组，
    int[] addIndexs;//用与设置其将添加的字段组

    public SimpleTableTransform(AbstractImpExpTableDefinition table) {
        super(table);
    }


    public void addIndex(int index, FieldGenerator valueGenerator) {
    }

    public void ignoreIndex(int index) {

    }

    public void ignoreIndexs(int[] index) {

    }

    @Override
    public Object[] getData(int rowIndex) {
        ArrayList adata = new ArrayList();
        ArrayList removedata = new ArrayList();
        Object[] datas = defaultTable.getData(rowIndex);
        for (int i = 0; i < datas.length; i++)
            adata.add(datas[i]);
        int[] base = defaultTable.getFieldIndexs();

        for (int i = 0; i < base.length; i++) {
            for (int j = 0; j < this.ignoreIndexs.length; j++) {
                if (ignoreIndexs[j] == base[i]) {
                    removedata.add(adata.get(i));
                }
            }
        }
        adata.removeAll(removedata);
        return adata.toArray();
    }

    @Override
    public int[] getFieldIndexs() {
        int[] base = defaultTable.getFieldIndexs();
        List<Integer> s1 = new ArrayList<Integer>();
        List<Integer> s2 = new ArrayList<Integer>();
        for (int i = 0; i < base.length; i++) {
            s1.add(base[i]);
        }
        for (int i = 0; i < ignoreIndexs.length; i++) {
            s2.add(ignoreIndexs[i]);
        }
        s1.removeAll(s2);
        int[] transIndexs = new int[s1.size()];
        for (int i = 0; i < s1.size(); i++)
            transIndexs[i] = s1.get(i).intValue();
        return transIndexs;
    }

    @Override
    public int[] getUpdateFieldIndexs() {
        int[] base = defaultTable.getUpdateFieldIndexs();
        List<Integer> s1 = new ArrayList<Integer>();
        List<Integer> s2 = new ArrayList<Integer>();
        for (int i = 0; i < base.length; i++) {
            s1.add(base[i]);
        }
        for (int i = 0; i < ignoreIndexs.length; i++) {
            s2.add(ignoreIndexs[i]);
        }
        s1.removeAll(s2);
        int[] transIndexs = new int[s1.size()];
        for (int i = 0; i < s1.size(); i++)
            transIndexs[i] = s1.get(i).intValue();
        return transIndexs;
    }
}
